Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sitemap

Package Overview
Dependencies
Maintainers
1
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sitemap

Sitemap-generating framework

  • 3.2.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
864K
increased by11.14%
Maintainers
1
Weekly downloads
 
Created

What is sitemap?

The sitemap npm package is a powerful tool for generating XML sitemaps for your website. It helps search engines like Google to better understand the structure of your site and improve its indexing. The package supports various features such as creating sitemaps, adding URLs, and generating sitemap indices.

What are sitemap's main functionalities?

Creating a Sitemap

This feature allows you to create a basic sitemap with a few URLs. The SitemapStream class is used to create a stream, and URLs are added using the write method. Finally, the stream is ended and written to a file.

const { SitemapStream, streamToPromise } = require('sitemap');
const { createWriteStream } = require('fs');

const sitemap = new SitemapStream({ hostname: 'https://example.com' });
const writeStream = createWriteStream('./sitemap.xml');
sitemap.pipe(writeStream);

sitemap.write({ url: '/page-1/', changefreq: 'daily', priority: 0.8 });
sitemap.write({ url: '/page-2/', changefreq: 'weekly', priority: 0.5 });
sitemap.end();

streamToPromise(writeStream).then(() => console.log('Sitemap created successfully.'));

Adding URLs Dynamically

This feature demonstrates how to add URLs to the sitemap dynamically from an array. This is useful when you have a list of URLs that you want to include in your sitemap.

const { SitemapStream, streamToPromise } = require('sitemap');
const { createWriteStream } = require('fs');

const sitemap = new SitemapStream({ hostname: 'https://example.com' });
const writeStream = createWriteStream('./sitemap.xml');
sitemap.pipe(writeStream);

const urls = [
  { url: '/page-1/', changefreq: 'daily', priority: 0.8 },
  { url: '/page-2/', changefreq: 'weekly', priority: 0.5 }
];

urls.forEach(url => sitemap.write(url));
sitemap.end();

streamToPromise(writeStream).then(() => console.log('Sitemap created successfully.'));

Generating a Sitemap Index

This feature allows you to create a sitemap index, which is useful for large websites that have multiple sitemaps. The SitemapIndexStream class is used to create the index, and individual sitemaps are added using the write method.

const { SitemapIndexStream, streamToPromise } = require('sitemap');
const { createWriteStream } = require('fs');

const sitemapIndex = new SitemapIndexStream();
const writeStream = createWriteStream('./sitemap-index.xml');
sitemapIndex.pipe(writeStream);

sitemapIndex.write({ url: 'https://example.com/sitemap-1.xml', lastmod: '2023-01-01' });
sitemapIndex.write({ url: 'https://example.com/sitemap-2.xml', lastmod: '2023-01-02' });
sitemapIndex.end();

streamToPromise(writeStream).then(() => console.log('Sitemap index created successfully.'));

Other packages similar to sitemap

Keywords

FAQs

Package last updated on 10 Jul 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc